package member

import (
	"gitee.com/micro-plat/sso/apiserver/api/modules/biz/member"
	"gitee.com/micro-plat/sso/apiserver/api/modules/const/field"
	"github.com/micro-plat/hydra"
)

//AuditInfoHandler 获取用户信息处理服务
type MemberHandler struct {
	loginRequiredFields []string
}

func NewMemberHandler() *MemberHandler {
	return &MemberHandler{
		loginRequiredFields: []string{"user_name", "password"},
	}
}

//LoginHandle  保存用户信息数据
func (u *MemberHandler) LoginHandle(ctx hydra.IContext) (r interface{}) {

	ctx.Log().Info("--------用户登录数据--------")

	ctx.Log().Info("1.检查必须字段")
	if err := ctx.Request().Check(u.loginRequiredFields...); err != nil {
		return err
	}

	ctx.Log().Info("2.用户登录")
	state, err := member.Login(ctx.Request().GetString(field.UserName),
		ctx.Request().GetString(field.Password),
		ctx.Request().GetString(field.Ident))
	if err != nil {
		return err
	}
	ctx.User().Auth().Response(state)
	return state
}
